#pragma once
#include "stdafx.h"

class TcpSocket
{
public:
    int m_connfd;
    struct sockaddr_in m_cliaddr;
    TcpSocket(int connfd, struct sockaddr_in cliaddr);

    int SendBuffer(const void *buf, int len);
    int RecvBuffer(void *buf, int len);

    template <typename T>
    int Send(const T *t)
    {
        return SendBuffer(t, sizeof(T));
    }

    template <typename T>
    int Recv(T *t)
    {
        return RecvBuffer(t, sizeof(T));
    }

    void OnClose();
};
